package com.yida.gwj.common.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yida.common.core.utils.DateUtils;
import com.yida.common.security.utils.SecurityUtils;
import com.yida.gwj.common.domain.GwjBaseHouse;
import com.yida.gwj.common.domain.dto.GwjBaseHouseDTO;
import com.yida.gwj.common.domain.dto.GwjBaseHouseSstatisticsDTO;
import com.yida.gwj.common.domain.dto.GwjBaseOwnerListDTO;
import com.yida.gwj.common.domain.request.GwjBaseHouseRequest;
import com.yida.gwj.common.domain.request.GwjBaseOwnerQueryRequest;
import com.yida.gwj.common.mapper.GwjBaseHouseMapper;
import com.yida.gwj.common.service.IGwjBaseHouseService;

/**
 * 基础数据（房屋）Service业务层处理
 *
 * @author lqq
 * @date 2022-11-14
 */
@Service
public class GwjBaseHouseServiceImpl implements IGwjBaseHouseService {

    @Autowired
    private GwjBaseHouseMapper houseMapper;

    /**
     * 查询基础数据（房屋）
     *
     * @param id 基础数据（房屋）主键
     * @return 基础数据（房屋）
     */
    @Override
    public GwjBaseHouse selectGwjBaseHouseByGwjBaseHouseId(Long id) {
        return houseMapper.selectGwjBaseHouseByGwjBaseHouseId(id);
    }

    /**
     * 查询基础数据（房屋）列表
     *
     * @param house 基础数据（房屋）
     * @return 基础数据（房屋）
     */
    @Override
    public List<GwjBaseHouse> selectGwjBaseHouseList(GwjBaseHouse house) {
        return houseMapper.selectGwjBaseHouseList(house);
    }

    /**
     * 根据楼栋标识码和地区ID查询房屋集合
     *
     * @param buildCodes 楼栋标识码集合
     * @param areaId 地区ID
     * @return /
     */
    @Override
    public List<GwjBaseHouse> selectGwjBaseListByBuildCodesAndAreaId(String[] buildCodes, Long areaId) {
        return houseMapper.selectGwjBaseListByBuildCodesAndAreaId(buildCodes, areaId);
    }

    /**
     * 新增基础数据（房屋）
     *
     * @param house 基础数据（房屋）
     * @return 结果
     */
    @Override
    public int insertGwjBaseHouse(GwjBaseHouse house) {
        house.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
        house.setCreateTime(DateUtils.getNowDate());
        return houseMapper.insertGwjBaseHouse(house);
    }

    /**
     * 批量新增基础数据（房屋）
     *
     * @param houses 基础数据（房屋）
     * @return 结果
     */
    @Override
    public int insertBatchGwjBaseHouse(List<GwjBaseHouse> houses) {
        return houseMapper.insertBatchGwjBaseHouse(houses);
    }

    /**
     * 修改基础数据（房屋）
     *
     * @param house 基础数据（房屋）
     * @return 结果
     */
    @Override
    public int updateGwjBaseHouse(GwjBaseHouse house) {
        house.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
        house.setUpdateTime(DateUtils.getNowDate());
        return houseMapper.updateGwjBaseHouse(house);
    }

    /**
     * 修改基础数据（房屋）
     *
     * @param gwjBaseHouses 基础数据（房屋）
     * @return 结果
     */
    @Override
    public int updateBatchGwjBaseHouse(List<GwjBaseHouse> gwjBaseHouses) {
        return houseMapper.updateBatchGwjBaseHouse(gwjBaseHouses);
    }

    /**
     * 修改基础数据（房屋）
     *
     * @param gwjBaseHouses 基础数据（房屋）
     * @return 结果
     */
    @Override
    public int updateBatchGwjBaseHouseByHouseCode(List<GwjBaseHouse> gwjBaseHouses) {
        return houseMapper.updateBatchGwjBaseHouseByHouseCode(gwjBaseHouses);
    }

    /**
     * 批量删除基础数据（房屋）
     *
     * @param ids 需要删除的基础数据（房屋）主键
     * @return 结果
     */
    @Override
    public int deleteGwjBaseHouseByGwjBaseHouseIds(Long[] ids) {
        return houseMapper.deleteGwjBaseHouseByGwjBaseHouseIds(ids);
    }

    /**
     * 删除基础数据（房屋）信息
     *
     * @param id 基础数据（房屋）主键
     * @return 结果
     */
    @Override
    public int deleteGwjBaseHouseByGwjBaseHouseId(Long id) {
        return houseMapper.deleteGwjBaseHouseByGwjBaseHouseId(id);
    }

    /************************* 新功能保留区 ************************************/

    /**
     * 根据项目编号查询基础数据（房屋）列表
     *
     * @param houseRequest 项目编号
     */
    @Override
    public List<GwjBaseHouseDTO> queryGwjBaseHouseListByParam(GwjBaseHouseRequest houseRequest) {
        return houseMapper.queryGwjBaseHouseListByParam(houseRequest);
    }

    /**
     * 根据参数查询房屋统计数据
     * 
     * @param houseRequest
     * @return
     */
    @Override
    public GwjBaseHouseSstatisticsDTO queryGwjBaseHouseStatisticsByParam(GwjBaseHouseRequest houseRequest) {
        return houseMapper.queryGwjBaseHouseStatisticsByParam(houseRequest);
    }

    @Override
    public GwjBaseHouse selectGwjBaseHouseByLocation(String location, String buildCode) {
        return houseMapper.selectGwjBaseHouseByLocation(location, buildCode);
    }

    @Override
    public int insertImportGwjBaseHouse(List<GwjBaseHouse> houses) {
        return houseMapper.insertImportGwjBaseHouse(houses);
    }

    @Override
    public int updateImportGwjBaseHouse(List<GwjBaseHouse> houses) {
        return houseMapper.updateImportGwjBaseHouse(houses);
    }

    @Override
    public boolean hasGwjBaseHouseByBuildCode(String buildCode) {
        // int result = houseMapper.hasGwjBaseHouseByBuildCode(buildCode);
        return houseMapper.hasGwjBaseHouseByBuildCode(buildCode) > 0;
    }

    @Override
    public int deleteGwjBaseHouseByHouseCodes(String[] houseCodes) {
        return houseMapper.deleteGwjBaseHouseByHouseCodes(houseCodes);
    }

    /************************* 新功能保留区 ************************************/

    /**
     * 根据房屋编号查询房屋信息
     * 
     * @param houseIds 房屋主键
     * @return
     */
    @Override
    public List<GwjBaseHouse> selectGwjBaseHoseByHouseIds(Long[] houseIds) {
        return houseMapper.selectGwjBaseHoseByHouseIds(houseIds);
    }

    /**
     * 根据房屋编号查询房屋信息
     * 
     * @param houseCodes 房屋编号
     * @return
     */
    @Override
    public List<GwjBaseHouse> selectGwjBaseListByHouseCode(String[] houseCodes) {
        return houseMapper.selectGwjBaseListByHouseCode(houseCodes);
    }

    @Override
    public List<GwjBaseHouse> selectGwjBaseListByCommunityId(Long communityId) {
        return houseMapper.selectGwjBaseListByCommunityId(communityId);
    }

    /**
     * 根据小区ID查询业主信息（含房屋数据）
     *
     * @param request 请求
     * @return /
     */
    @Override
    public List<GwjBaseOwnerListDTO> selectGwjBaseOwnerDtoListByCommunityId(GwjBaseOwnerQueryRequest request) {
        return houseMapper.selectGwjBaseOwnerDtoListByCommunityId(request);
    }
}
